package com.blog.entity;

import java.io.Serializable;

import java.math.BigDecimal;

import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.IdType;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.blog.myUtils.DateTime;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *
 * </p>
 *
 * @author mars123
 * @since 2019-07-02
 */
@TableName("ssm.order")
public class Order extends Model<Order> {

    private static final long serialVersionUID = 1L;
    public static final int STATUS_UNPAY = 0;
    public static final int STATUS_PAYED = 1;
    public static final int STATUS_DEVELIVERING = 2;
    public static final int STATUS_FINISH = 3;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;
    @TableField("out_trade_no")
    private String outTradeNo;
    private Integer uid;
    /**
     * 总价
     */
    private BigDecimal mount;
    /**
     * 状态
     */
    private Integer status;
    @TableField("created_at")
    private Integer createdAt;


    public String getCreatedTime() {
        return createdAt == null ? "-" : DateTime.format(createdAt);
    }

    public List<OrderTail> getTails() {
        return id != null ? new OrderTail().selectList(new EntityWrapper().eq("order_id", id)) : null;
    }

    public User getUser() {
        return uid == null ? null : new User().selectById(uid);
    }

    public Map<Integer, String> getStatusList() {
        Map<Integer, String> map = new HashMap<Integer, String>();
        map.put(STATUS_UNPAY, "未支付");
        map.put(STATUS_PAYED, "已支付");
        map.put(STATUS_DEVELIVERING, "配送中");
        map.put(STATUS_FINISH, "已完成");
        return map;
    }

    public String getStatusName() {
        Map<Integer, String> map = getStatusList();
        return status != null ? map.get(status) : null;
    }


    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getOutTradeNo() {
        return outTradeNo;
    }

    public void setOutTradeNo(String outTradeNo) {
        this.outTradeNo = outTradeNo;
    }

    public Integer getUid() {
        return uid;
    }

    public void setUid(Integer uid) {
        this.uid = uid;
    }

    public BigDecimal getMount() {
        return mount;
    }

    public void setMount(BigDecimal mount) {
        this.mount = mount;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Integer getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Integer createdAt) {
        this.createdAt = createdAt;
    }

    @Override
    protected Serializable pkVal() {
        return this.id;
    }

    @Override
    public String toString() {
        return "Order{" +
                "id=" + id +
                ", outTradeNo=" + outTradeNo +
                ", uid=" + uid +
                ", mount=" + mount +
                ", status=" + status +
                ", createdAt=" + createdAt +
                "}";
    }
}
